package com.ruoyi.web.controller.fantasy;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyUserTitle;
import com.ruoyi.fantasy.service.ITitlesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * fantasy用户称号 信息操作处理
 * 
 * @author wanghui
 * @date 2019-07-05
 */
@Controller
@RequestMapping("/fantasy/titles")
public class TitlesController extends BaseController
{
    private String prefix = "fantasy/titles";
	
	@Autowired
	private ITitlesService titlesService;
	
	@RequiresPermissions("fantasy:titles:view")
	@GetMapping()
	public String titles()
	{
	    return prefix + "/titles";
	}
	
	/**
	 * 查询fantasy用户称号列表
	 */
	@RequiresPermissions("fantasy:titles:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FantasyUserTitle titles)
	{
		startPage();
        List<FantasyUserTitle> list = titlesService.selectTitlesList(titles);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出fantasy用户称号列表
	 */
	@RequiresPermissions("fantasy:titles:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyUserTitle titles)
    {
    	List<FantasyUserTitle> list = titlesService.selectTitlesList(titles);
        ExcelUtil<FantasyUserTitle> util = new ExcelUtil<FantasyUserTitle>(FantasyUserTitle.class);
        return util.exportExcel(list, "titles");
    }
	
	/**
	 * 新增fantasy用户称号
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存fantasy用户称号
	 */
	@RequiresPermissions("fantasy:titles:add")
	@Log(title = "fantasy用户称号", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FantasyUserTitle titles)
	{		
		return toAjax(titlesService.insertTitles(titles));
	}

	/**
	 * 修改fantasy用户称号
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		FantasyUserTitle titles = titlesService.selectTitlesById(id);
		mmap.put("titles", titles);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存fantasy用户称号
	 */
	@RequiresPermissions("fantasy:titles:edit")
	@Log(title = "fantasy用户称号", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FantasyUserTitle titles)
	{		
		return toAjax(titlesService.updateTitles(titles));
	}
	
	/**
	 * 删除fantasy用户称号
	 */
	@RequiresPermissions("fantasy:titles:remove")
	@Log(title = "fantasy用户称号", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(titlesService.deleteTitlesByIds(ids));
	}
	
}
